/////////////////////////////////////////////////////////////////////////////
// Name:        quickconnect.cpp
// Purpose:     
// Author:      Stephen Whittle
// Modified by: 
// Created:     20/06/2009 19:20:46
// RCS-ID:      
// Copyright:   
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "quickconnect.h"
#include "globals.h"
////@begin XPM images
////@end XPM images


/*
 * QuickConnect type definition
 */

IMPLEMENT_DYNAMIC_CLASS( QuickConnect, wxDialog )


/*
 * QuickConnect event table definition
 */

BEGIN_EVENT_TABLE( QuickConnect, wxDialog )

////@begin QuickConnect event table entries
    EVT_TEXT_ENTER( ID_TEXTCTRL3, QuickConnect::OnOkClick )

    EVT_TEXT_ENTER( ID_TEXTCTRL4, QuickConnect::OnOkClick )

    EVT_BUTTON( wxID_OK, QuickConnect::OnOkClick )

////@end QuickConnect event table entries

END_EVENT_TABLE()


/*
 * QuickConnect constructors
 */

QuickConnect::QuickConnect()
{
    Init();
}

QuickConnect::QuickConnect( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*
 * QuickConnect creator
 */

bool QuickConnect::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin QuickConnect creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end QuickConnect creation
    return true;
}


/*
 * QuickConnect destructor
 */

QuickConnect::~QuickConnect()
{
////@begin QuickConnect destruction
////@end QuickConnect destruction
}


/*
 * Member initialisation
 */

void QuickConnect::Init()
{
////@begin QuickConnect member initialisation
    m_Server = NULL;
    m_Port = NULL;
////@end QuickConnect member initialisation
}


/*
 * Control creation for QuickConnect
 */

void QuickConnect::CreateControls()
{    
////@begin QuickConnect content construction
    QuickConnect* itemDialog1 = this;

    wxFlexGridSizer* itemFlexGridSizer2 = new wxFlexGridSizer(0, 2, 0, 0);
    itemFlexGridSizer2->AddGrowableCol(1);
    itemDialog1->SetSizer(itemFlexGridSizer2);

    wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1, wxID_STATIC, _("Server:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer2->Add(itemStaticText3, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_Server = new wxTextCtrl( itemDialog1, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
    itemFlexGridSizer2->Add(m_Server, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Port:"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer2->Add(itemStaticText5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_Port = new wxTextCtrl( itemDialog1, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
    itemFlexGridSizer2->Add(m_Port, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    itemFlexGridSizer2->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer8 = new wxStdDialogButtonSizer;

    itemFlexGridSizer2->Add(itemStdDialogButtonSizer8, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
    wxButton* itemButton9 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer8->AddButton(itemButton9);

    wxButton* itemButton10 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer8->AddButton(itemButton10);

    itemStdDialogButtonSizer8->Realize();

////@end QuickConnect content construction
 m_Server->SetValue(pConfig->Read(wxT("/QuickConnect/Server"),wxEmptyString));
 m_Port->SetValue(pConfig->Read(wxT("/QuickConnect/Port"),wxEmptyString));
 
}


/*
 * Should we show tooltips?
 */

bool QuickConnect::ShowToolTips()
{
    return true;
}

/*
 * Get bitmap resources
 */

wxBitmap QuickConnect::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin QuickConnect bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end QuickConnect bitmap retrieval
}

/*
 * Get icon resources
 */

wxIcon QuickConnect::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin QuickConnect icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end QuickConnect icon retrieval
}


/*
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
 */

void QuickConnect::OnOkClick( wxCommandEvent& event )
{
if ((m_Server->GetValue() != wxEmptyString) && (m_Port->GetValue() != wxEmptyString)){
pConfig->Write(wxT("/QuickConnect/Server"),m_Server->GetValue());
pConfig->Write(wxT("/QuickConnect/Port"),m_Port->GetValue());
pConfig->Flush();
this->EndModal(wxID_OK);
}else{
wxMessageBox(wxT("Please enter values in the Server and Port fields."));
}
//(this->GetParent())->PostMessage
}



